// This file is part of OpenTSDB.
// Copyright (C) 2017 TeleDB Development Group.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version.  This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.  You should have received a copy
// of the GNU Lesser General Public License along with this program.  If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.utils.aggregation;

import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;
import net.opentsdb.utils.Formats;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestAggregationTools {

    /**
     * 测试guava peekIterator，支持预览下一笔数据
     */
    @Test
    public void testPeekIterator(){
        List<Integer> list = Arrays.asList(1,3,2,7,8);

        PeekingIterator<Integer> iterator = Iterators.peekingIterator(list.iterator());

        while (iterator.hasNext()){
            int cur = iterator.next();
            if(iterator.hasNext()){
                int peek = iterator.peek();
                System.out.println("current:"+cur+" peek:"+peek+" cur-peek:"+(cur-peek));
            }
        }
    }

    @Test
    public void testDoubleConvertByte(){
        Double[] values = new Double[]{0.72d,100.12d,0.11d,0.00d,-1.01d,79.899101, 79.89401, 79.89510, Double.NaN};

        for(Double value : values){
            System.out.println(Formats.formatDouble(value));
        }
    }

    @Test
    public void testPattern(){
        Pattern pattern = Pattern.compile("tag1_1|tag1_2");

        String[] list = new String[]{"tag1_1","tag1_2"};
        for(String s: list){
            System.out.println(s+":"+pattern.matcher(s).find());
        }
    }
}
